package com.itheima.health.controller.user;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.pojo.UserOrder;
import com.itheima.health.result.Result;
import com.itheima.health.service.OrderService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/mobile/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 预约下单
     * @param userOrder
     * @return
     */
    @PostMapping("/submit")
    public Result sumbit(@RequestBody UserOrder userOrder){
        orderService.addOrder(userOrder);
        Map<String,Integer> orderId = new HashMap<>();
        orderId.put("id",userOrder.getId());

        return new Result(true, MessageConst.ORDERSETTING_SUCCESS,orderId);
    }

    /**
     * 根据orderId查询预订信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id) {
        Order order = orderService.findById(id);
        return new Result(true, MessageConst.QUERY_ORDER_SUCCESS, order);
    }
}
